namespace CSSharpPro._1009;

public class Demo2
{
    public void TestPrint()
    {
        //作业1 输出1000以内的水仙花数
        Console.WriteLine("1000以内的水仙花数：");
        for (int num = 100; num < 1000; num++)
        {
            int hundreds = num / 100;
            int tens = (num / 10) % 10;
            int units = num % 10;

            if (Math.Pow(hundreds, 3) + Math.Pow(tens, 3) + Math.Pow(units, 3) == num)
            {
                Console.Write(num + " ");
            }
        }
        Console.WriteLine();
    }

    public void TestPrint2()
    {
        //作业2 输出100以内所有的质数
        Console.WriteLine("100以内的所有质数：");
        for (int num = 2; num < 100; num++)
        {
            bool isPrime = true;
            for (int i = 2; i <= Math.Sqrt(num); i++)
            {
                if (num % i == 0)
                {
                    isPrime = false;
                    break;
                }
            }
            if (isPrime)
            {
                Console.Write(num +" ");
            }
        }
        Console.WriteLine();
    }
}